package com.cqupt.controller;

import com.alibaba.fastjson2.JSON;
import com.cqupt.model.constant.Constant;
import com.cqupt.model.pojo.Book;
import com.cqupt.model.vo.Result;
import com.cqupt.model.vo.ResultCodeEnum;
import com.cqupt.service.BookService;
import com.cqupt.utils.AuthContextUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/book")
@Tag(name = "词书模块")
public class BookController {

    @Resource
    private BookService bookService;

    @Resource
    private StringRedisTemplate stringRedisTemplate;


    @GetMapping("/all")
    @Operation(summary = "显示全部词书")
    public Result getAll() {

        List<Book> list = bookService.getAll();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/getByCategoryId")
    @Operation(summary = "词书分类")
    public Result getByCategoryId(@RequestParam("id") int id) {

        List<Book> list = bookService.getByCategoryId(id, null, null).getRecords();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }


    @GetMapping("/getBook")
    @Operation(summary = "选择词书接口")
    public Result getBook(@RequestParam int bookId) {

        Book book = bookService.getBook(bookId);


        return Result.build(book, ResultCodeEnum.SUCCESS);
    }


    @GetMapping("/queryBook")
    @Operation(summary = "查询词书")
    public Result queryBook(@RequestParam String title) {

        List<Book> book = bookService.queryBook(title);


        return Result.build(book, ResultCodeEnum.SUCCESS);
    }
}
